package cn.enilu.guns.admin.modular.door;

import cn.enilu.guns.bean.entity.door.EntranceGuardDoor;
import cn.enilu.guns.service.door.EntranceGuardDoorService;

import cn.enilu.guns.bean.annotion.core.BussinessLog;
import cn.enilu.guns.bean.constant.factory.PageFactory;
import cn.enilu.guns.bean.dictmap.CommonDict;
import cn.enilu.guns.admin.core.base.controller.BaseController;
import cn.enilu.guns.bean.exception.GunsException;

import cn.enilu.guns.bean.vo.query.Page;
import cn.enilu.guns.bean.vo.query.SearchFilter;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/door/ENTRANCE/GUARD/DOOR")
public class EntranceGuardDoorController extends BaseController {
	private  Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private EntranceGuardDoorService entranceGuardDoorService;

	private static String PREFIX = "/door/ENTRANCE/GUARD/DOOR/";

	/**
	* 跳转到首页
	*/
	@RequestMapping(value="",method = RequestMethod.GET)
		public String index() {
		return PREFIX + "index.html";
	}

	/**
	* 跳转到添加页面
	*/
	@RequestMapping(value = "/add",method = RequestMethod.GET)
		public String add() {
		return PREFIX + "add.html";
	}

	/**
	* 跳转到修改页面
	*/
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable Long id, Model model) {
		EntranceGuardDoor entity = entranceGuardDoorService.get(id);
		model.addAttribute("item",entity);
		return PREFIX + "edit.html";
	}
	@RequestMapping(value = "/list",method = RequestMethod.POST)
	@ResponseBody
	public Object list(@RequestParam(required = false) String name) {
		Page<EntranceGuardDoor> page = new PageFactory<EntranceGuardDoor>().defaultPage();
		page.addFilter("name", SearchFilter.Operator.EQ,name);
		page = entranceGuardDoorService.queryPage(page);
		return super.packForBT(page);
	}
	/**
	* 新增门与门禁权限对应表
	*/
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	@BussinessLog(value = "新增门与门禁权限对应表", key = "name",dict= CommonDict.class)
	public Object add(EntranceGuardDoor entranceGuardDoor) {
		entranceGuardDoorService.insert(entranceGuardDoor);
		return SUCCESS_TIP;
	}

	/**
	* 删除门与门禁权限对应表
	*/
	@RequestMapping(value = "/delete")
	@ResponseBody
	@BussinessLog(value = "删除门与门禁权限对应表", key = "id",dict= CommonDict.class)
	public Object delete(@RequestParam Long id) {
		entranceGuardDoorService.delete(id);
		return SUCCESS_TIP;
	}

	/**
	* 修改门与门禁权限对应表
	*/
	@RequestMapping(value = "/update")
	@ResponseBody
	@BussinessLog(value = "修改门与门禁权限对应表", key = "name",dict= CommonDict.class)
	public Object update(EntranceGuardDoor entranceGuardDoor) {
		entranceGuardDoorService.update(entranceGuardDoor);
		return SUCCESS_TIP;
	}

}